package com.biqee.util;

import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

public class EnvUtil {
	private static final Logger LOG = Logger.getLogger(EnvUtil.class);
	
	private static ResourceBundle res = null;
	
	private static final String CONFIG_NAME = "env";
	
	static {
		try {
			res = (PropertyResourceBundle) ResourceBundle.getBundle(CONFIG_NAME);
		} catch (Exception e) {
			LOG.error("load env failed. exception: ", e);
			res = null;
		}
		
		if(res == null) { 
			throw new RuntimeException("faileed in loading envirment value from configuration file  " + CONFIG_NAME);
		}
	}

	public static String get(String key) {
		try {
			return res.getString(key);
		} catch (MissingResourceException e) {
			LOG.error("get value failed, ", e);
			return null;
		}
	}
	
	public static String getWebUrl(){
		return get("webUrl");
	}
	
	public static String getStaticUrl(){
		return get("staticUrl");
	}
	
	public  static String getFileStore() {
		return get("file.store");
	}
	
	public  static String getStoreUrl() {
		return get("storeUrl");
	}
	
	public static boolean isTaskServer() {
		String isTaskServer = get("isTaskServer");
		return "y".equalsIgnoreCase(isTaskServer);
	}

	public static String getUserPassSalt() {
		String userPassSalt = get("bq_crm_salt");
		if(userPassSalt == null) {
			throw new RuntimeException("user pass salt missing!!!");
		}
		
		return userPassSalt;
	}
}
